<!DOCTYPE html>
<html>

<head>
  <title>Mocking CDI beans in Quarkus</title>
  <script id="adobe_dtm" src="https://www.redhat.com/dtm.js" type="text/javascript"></script>
  <script src="/assets/javascript/highlight.pack.js" type="text/javascript"></script>
  <META HTTP-EQUIV='Content-Security-Policy' CONTENT="default-src 'none'; script-src 'self' 'unsafe-eval' 'sha256-ANpuoVzuSex6VhqpYgsG25OHWVA1I+F6aGU04LoI+5s=' 'sha256-ipy9P/3rZZW06mTLAR0EnXvxSNcnfSDPLDuh3kzbB1w=' js.bizographics.com https://www.redhat.com assets.adobedtm.com jsonip.com https://ajax.googleapis.com https://www.googletagmanager.com https://www.google-analytics.com https://use.fontawesome.com; style-src 'self' https://fonts.googleapis.com https://use.fontawesome.com; img-src 'self' *; media-src 'self' ; frame-src https://www.googletagmanager.com https://www.youtube.com; frame-ancestors 'none'; base-uri 'none'; object-src 'none'; form-action 'none'; font-src 'self' https://use.fontawesome.com https://fonts.gstatic.com;">
  <META HTTP-EQUIV='X-Frame-Options' CONTENT="DENY">
  <META HTTP-EQUIV='X-XSS-Protection' CONTENT="1; mode=block">
  <META HTTP-EQUIV='X-Content-Type-Options' CONTENT="nosniff">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Quarkus: Supersonic Subatomic Java">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:site" content="@QuarkusIO"> 
  <meta name="twitter:creator" content="@QuarkusIO">
  <meta property="og:url" content="https://quarkus.io/blog/mocking/" />
  <meta property="og:title" content="Mocking CDI beans in Quarkus" />
  <meta property="og:description" content="Quarkus: Supersonic Subatomic Java" />
  <meta property="og:image" content="/assets/images/quarkus_card.png" />
  <link rel="canonical" href="https://quarkus.io/blog/mocking/">
  <link rel="shortcut icon" type="image/png" href="/favicon.ico" >
  <link rel="stylesheet" href="https://quarkus.io/guides/stylesheet/config.css" />
  <link rel="stylesheet" href="/assets/css/main.css" />
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  <link rel="alternate" type="application/rss+xml"  href="https://quarkus.io/feed.xml" title="Quarkus">
  <script src="https://quarkus.io/assets/javascript/goan.js" type="text/javascript"></script>
  <script src="https://quarkus.io/assets/javascript/hl.js" type="text/javascript"></script>
</head>

<body class="post">
  <!-- Google Tag Manager (noscript) -->
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NJWS5L"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <!-- End Google Tag Manager (noscript) -->

  <div class="nav-wrapper">
  <div class="grid-wrapper">
    <div class="width-12-12">
      <input type="checkbox" id="checkbox" />
      <nav id="main-nav" class="main-nav">
  <div class="container">
    <div class="logo-wrapper">
      
        <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_600px_reverse.png" class="project-logo" title="Quarkus"></a>
      
    </div>
    <label class="nav-toggle" for="checkbox">
      <i class="fa fa-bars"></i>
    </label>
    <div id="menu" class="menu">
      <span>
        <a href="/get-started/" class="">Get Started</a>
      </span>
      <span>
        <a href="/guides/" class="">Guides</a>
      </span>
      <span>
        <a href="/community/" class="">Community</a>
      </span>
      <span>
        <a href="/support/" class="">Support</a>
      </span>
      <span>
        <a href="/blog/" class="active">Blog</a>
      </span>
      <span>
        <a href="https://code.quarkus.io" class="button-cta secondary white">Start Coding</a>
      </span>
    </div>
  </div>
      </nav>
    </div>
  </div>
</div>

  <div class="content">
    <div class="post-page grid-wrapper">
  <div class="width-8-12 width-12-12-m doc-content">
    <div class="grid-wrapper">
      <div class="width-12-12">
        <p>
          <a href="/blog"><i class="fas fa-angle-left"></i> Back to all posts</a>
        </p>
      </div>
      <div class="width-12-12">
        <div class="post-date">
          April 28, 2020 
          
            <span class="tags"><a href="/blog/tag/testing">#testing</a></span>
          
        </div>
        <h1 class="post-title">Mocking CDI beans in Quarkus</h1>
        <div class="grid-wrapper">
          <div class="width-8-12 width-12-12-m byline-wrapper">
            
            
              <img class="headshot" src="https://www.gravatar.com/avatar/dd57c2732aea5fe7eb686d17cfe14b44">
            
            <p class="byline">By Georgios Andrianakis</p>
          </div>
          <div class="width-12-12">
              <div class="paragraph">
<p>Testing Quarkus applications has been an important part of the Quarkus Developer Joy, which is why
<code>@QuarkusTest</code> for testing JVM applications and <code>@NativeTest</code> for black-box testing of the native images have been
part of Quarkus since the first release.
A recurring request however amongst our community members has been to have Quarkus allow them to selectively
mock certain CDI beans for specific tests. This post will introduce the new mocking capabilities
that <code>1.4</code> brings which aim to address those concerns, while also providing a glimpse of additional
improvements in this are that will be part of <code>1.5</code>.</p>
</div>
<div class="sect1">
<h2 id="old-approach"><a class="anchor" href="#old-approach"></a>Old approach</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Let us assume that a Quarkus application contains the following (purely contrived) bean:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@ApplicationScoped
public class OrderService {

    private final InvoiceService invoiceService;
    private final InvoiceNotificationService invoiceNotificationService;

    public OrderService(InvoiceService invoiceService, InvoiceNotificationService invoiceNotificationService) {
        this.invoiceService = invoiceService;
        this.invoiceNotificationService = invoiceNotificationService;
    }

    public Invoice generateSendInvoice(Long orderId) {
        final Invoice invoice = invoiceService.generateForOrder(orderId);
        if (invoice.isAlreadySent()) {
            invoiceNotificationService.sendInvoice(invoice);
        } else {
            invoiceNotificationService.notifyInvoiceAlreadySent(invoice);
        }
        return invoice;
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>When testing the <code>generateSendInvoice</code> method we most likely don&#8217;t want to use the actual <code>InvoiceNotificationService</code> as it would
result in sending real notifications. With the old Quarkus approach one could "override"
the <code>InvoiceNotificationService</code> in tests by adding the following bean in the test sources:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Mock
public class MockInvoiceNotificationService implements InvoiceNotificationService {

    public void sendInvoice(Invoice invoice) {

    }

    public void notifyInvoiceAlreadySent(Invoice invoice) {

    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>When Quarkus scanned this code, the use of <code>@Mock</code> would result in <code>MockInvoiceNotificationService</code> being used as
the implementation of <code>InvoiceNotificationService</code> in every place where a <code>InvoiceNotificationService</code> bean was injected
(in CDI terms this is called an injection point).</p>
</div>
<div class="paragraph">
<p>Although this mechanism is fairly straightforward to use, it nonetheless suffers from a few problems:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A new class (or a new CDI producer method) needs to be used for each bean type that requires a mock. In a large application where a lot of
mocks are needed, the amount of boilerplate code increases unacceptably.</p>
</li>
<li>
<p>There is no way for a mock to be used for certain tests only. This is due to the fact that beans that are annotated with <code>@Mock</code> are normal
CDI beans (and are therefore used throughout the application).
Depending on what needs to be tested, this can be very problematic.</p>
</li>
<li>
<p>There is a no out of the box integration with <a href="https://site.mockito.org/">Mockito</a>, which is the de-facto standard for
mocking in Java applications. Users can certainly use Mockito (most commonly by using a CDI producer method), but there
is boilerplate code involved.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="new-approach"><a class="anchor" href="#new-approach"></a>New approach</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Starting with Quarkus <code>1.4</code>, users have the ability to create and inject per-test mocks for normal scoped CDI beans using
<code>io.quarkus.test.junit.QuarkusMock</code>. Moreover, Quarkus provides out of the box integration with Mockito
allowing for zero effort mocking of CDI beans using the <code>io.quarkus.test.junit.mockito.@InjectMock</code> annotation.</p>
</div>
<div class="sect2">
<h3 id="using-quarkusmock"><a class="anchor" href="#using-quarkusmock"></a>Using QuarkusMock</h3>
<div class="paragraph">
<p><code>QuarkusMock</code> provides the foundation for mocking normal scoped CDI beans and is also used under the hood by <code>@InjectMock</code>, so let us examine
it first. The best way to do this is using an example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@QuarkusTest
public class MockTestCase {

    @Inject
    MockableBean1 mockableBean1;

    @Inject
    MockableBean2 mockableBean2;

    @BeforeAll
    public static void setup() {
        MockableBean1 mock = Mockito.mock(MockableBean1.class);  <i class="conum" data-value="1"></i><b>(1)</b>
        Mockito.when(mock.greet("Stuart")).thenReturn("A mock for Stuart");
        QuarkusMock.installMockForType(mock, MockableBean1.class);  <i class="conum" data-value="2"></i><b>(2)</b>
    }

    @Test
    public void testBeforeAll() {
        Assertions.assertEquals("A mock for Stuart", mockableBean1.greet("Stuart"));  <i class="conum" data-value="3"></i><b>(3)</b>
        Assertions.assertEquals("Hello Stuart", mockableBean2.greet("Stuart")); <i class="conum" data-value="4"></i><b>(4)</b>
    }

    @Test
    public void testPerTestMock() {
        QuarkusMock.installMockForInstance(new BonjourMockableBean2(), mockableBean2); <i class="conum" data-value="5"></i><b>(5)</b>
        Assertions.assertEquals("A mock for Stuart", mockableBean1.greet("Stuart"));  <i class="conum" data-value="6"></i><b>(6)</b>
        Assertions.assertEquals("Bonjour Stuart", mockableBean2.greet("Stuart")); <i class="conum" data-value="7"></i><b>(7)</b>
    }

    @ApplicationScoped
    public static class MockableBean1 {

        public String greet(String name) {
            return "Hello " + name;
        }
    }

    @ApplicationScoped
    public static class MockableBean2 {

        public String greet(String name) {
            return "Hello " + name;
        }
    }

    public static class BonjourMockableBean2 extends MockableBean2 {
        @Override
        public String greet(String name) {
            return "Bonjour " + name;
        }
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>This part of the  example uses Mockito for convenience&#8217;s sake only. <code>QuarkusMock</code> is not tied to Mockito in any way.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>We use <code>QuarkusMock.installMockForType()</code> because the injected bean instance is not yet available. Very important to note is that
the mock setup in a JUnit <code>@BeforeAll</code> method, is used for <strong>all</strong> test methods of the class (other test classes are <strong>not</strong> affected by this).</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>The mock for <code>MockableBean1</code> is being used as it was defined for all test methods of the class.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>Since no mock has been set up for <code>MockableBean2</code>, the CDI bean is being used.</td>
</tr>
<tr>
<td><i class="conum" data-value="5"></i><b>5</b></td>
<td>We use <code>QuarkusMock.installMockForInstance()</code> here because inside the test method, the injected bean instance is available.</td>
</tr>
<tr>
<td><i class="conum" data-value="6"></i><b>6</b></td>
<td>The mock for <code>MockableBean1</code> is being used as it was defined for all test methods of the class.</td>
</tr>
<tr>
<td><i class="conum" data-value="7"></i><b>7</b></td>
<td>As we used <code>BonjourMockableBean2</code> as a mock <code>MockableBean2</code>, this class is now used.</td>
</tr>
</table>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
<div class="paragraph">
<p><code>QuarkusMock</code> can be used for any normal scoped CDI bean - the most common of which are <code>@ApplicationScoped</code> and <code>@RequestScoped</code>.
This means that beans with <code>@Singleton</code> and <code>@Dependent</code> scope <strong>cannot</strong> be used with <code>QuarkusMock</code>.</p>
</div>
<div class="paragraph">
<p>Furthermore, <code>QuarkusMock</code> will not work properly when it&#8217;s used in tests that run parallel in the same JVM.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Returning to the original example of the blog post, we could get rid of the <code>MockInvoiceNotificationService</code> class and
instead use something like the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">public class OrderServiceTest {

    @Inject
    OrderService orderService;

    @BeforeAll
    public static void setup() {
        MockableBean1 mock = Mockito.mock(InvoiceNotificationService.class);
        Mockito.doNothing().when(mock).sendInvoice(any());
        Mockito.doNothing().when(mock).notifyInvoiceAlreadySent(any());
        QuarkusMock.installMockForType(mock, MockableBean1.class);
    }

    public void testGenerateSendInvoice() {
        // perform some setup

        Invoice invoice = orderService.generateSendInvoice(1L);

        // perform some assertions
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note that in this case we don&#8217;t need to create a new class implementing <code>InvoiceNotificationService</code>.
Moreover, we have full and per test control over the mock, something which grants up a lot of flexibility when writing tests.</p>
</div>
<div class="paragraph">
<p>For example, if we had some other test where we did want to use the real <code>InvoiceNotificationService</code>, then in that test
we would simply not do any mocking of <code>InvoiceNotificationService</code>.</p>
</div>
<div class="paragraph">
<p>If yet another test needed to mock <code>InvoiceNotificationService</code> in some other way, then it would be perfectly free to do so,
using the same method <code>OrderServiceTest</code> uses, without causing any problems to the other tests.</p>
</div>
<div class="paragraph">
<p>Finally, note in the example above we didn&#8217;t mock <code>InvoiceService</code>, which meant that the real <code>InvoiceService</code> was being used in <code>OrderServiceTest</code>.</p>
</div>
</div>
<div class="sect2">
<h3 id="using-injectmock"><a class="anchor" href="#using-injectmock"></a>Using @InjectMock</h3>
<div class="paragraph">
<p>Hopefully the previous section convinced you of the merits of <code>QuarkusMock</code> over the old approach. You might also be wondering
however if there is a way to reduce boilerplate code even further and provide tighter integration with Mockito. That is
where <code>@InjectMock</code> comes in handy.</p>
</div>
<div class="paragraph">
<p>To demonstrate <code>@InjectMock</code> let&#8217;s rewrite the <code>MockTestCase</code> from the previous section.</p>
</div>
<div class="paragraph">
<p>First of all, we need to add the following dependency:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs">&lt;dependency&gt;
    &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
    &lt;artifactId&gt;quarkus-junit5-mockito&lt;/artifactId&gt;
    &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Now we can rewrite the <code>MockTestCase</code> like so:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@QuarkusTest
public class MockTestCase {

    @InjectMock
    MockableBean1 mockableBean1; <i class="conum" data-value="1"></i><b>(1)</b>

    @InjectMock
    MockableBean2 mockableBean2;

    @BeforeEach
    public void setup() {
        Mockito.when(mockableBean1.greet("Stuart")).thenReturn("A mock for Stuart"); <i class="conum" data-value="2"></i><b>(2)</b>
    }

    @Test
    public void firstTest() {
        Assertions.assertEquals("A mock for Stuart", mockableBean1.greet("Stuart"));
        Assertions.assertEquals(null, mockableBean2.greet("Stuart"));
    }

    @Test
    public void secondTest() {
        Mockito.when(mockableBean2.greet("Stuart")).thenReturn("Bonjour Stuart"); <i class="conum" data-value="3"></i><b>(3)</b>
        Assertions.assertEquals("A mock for Stuart", mockableBean1.greet("Stuart"));
        Assertions.assertEquals("Bonjour Stuart", mockableBean2.greet("Stuart"));
    }

    @ApplicationScoped
    public static class MockableBean1 {

        public String greet(String name) {
            return "Hello " + name;
        }
    }

    @ApplicationScoped
    public static class MockableBean2 {

        public String greet(String name) {
            return "Hello " + name;
        }
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>@InjectMock</code> results in a mock being created and being available in <strong>all</strong> test methods of the test class (other test classes are <strong>not</strong> affected by this)</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The <code>mockableBean1</code> is configured here for all test methods of the class</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Configure <code>mockableBean2</code> for this test only</td>
</tr>
</table>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Since <code>@InjectMock</code> uses <code>QuarkusMock</code> under the hood, the same limitations apply to its use.</p>
</div>
<div class="paragraph">
<p>Additionally, <code>@InjectMock</code> works like an injection point for the bean, so for it to work properly when
the target bean uses CDI qualifiers, those qualifiers also need to be added to the field.
We will see an example of this in next section about mocking a <code>@RestClient</code> bean.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>As a final example, we can rewrite the <code>OrderServiceTest</code> test like so:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">public class OrderServiceTest {

    @Inject
    private OrderService orderService;

    @InjectMock
    private InvoiceNotificationService invoiceNotificationService;

    @BeforeAll
    public static void setup() {
        doNothing().when(invoiceNotificationService).sendInvoice(any());
        doNothing().when(invoiceNotificationService).notifyInvoiceAlreadySent(any());
    }

    public void testGenerateSendInvoice() {
        // perform some setup

        Invoice invoice = orderService.generateSendInvoice(1L);

        // perform some assertions
    }
}</code></pre>
</div>
</div>
<div class="sect3">
<h4 id="using-injectmock-with-restclient"><a class="anchor" href="#using-injectmock-with-restclient"></a>Using @InjectMock with @RestClient</h4>
<div class="paragraph">
<p>A very common need is to mock <code>@RestClient</code> beans. Thankfully it&#8217;s a need well covered by <code>@InjectMock</code> - as long
as two principles are followed:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The bean is made <code>@ApplicationScoped</code> (instead of accepting the default scope which <code>@RegisterRestClient</code> implies, i.e. <code>@Dependent</code>)</p>
</li>
<li>
<p>The <code>@RestClient</code> CDI qualifier is used when injecting the bean into the test.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>As usual, an example best demonstrates these requirements. Say we have a <code>GreetingService</code> which we wish to use to build a rest client:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Path("/")
@ApplicationScoped  <i class="conum" data-value="1"></i><b>(1)</b>
@RegisterRestClient
public interface GreetingService {

    @GET
    @Path("/hello")
    @Produces(MediaType.TEXT_PLAIN)
    String hello();
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>@ApplicationScoped</code> needs to be used to make <code>GreetingService</code> mockable.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>An example test class could be:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@QuarkusTest
public class GreetingResourceTest {

    @InjectMock
    @RestClient <i class="conum" data-value="1"></i><b>(1)</b>
    GreetingService greetingService;

    @Test
    public void testHelloEndpoint() {
        Mockito.when(greetingService.hello()).thenReturn("hello from mockito");

        given()
          .when().get("/hello")
          .then()
             .statusCode(200)
             .body(is("hello from mockito"));
    }

}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>We need to use the <code>@RestClient</code> CDI qualifier, since Quarkus creates the <code>GreetingService</code> bean with this qualifier.</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="more-mocking-in-quarkus-1-5"><a class="anchor" href="#more-mocking-in-quarkus-1-5"></a>More Mocking in Quarkus 1.5</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Quarkus 1.5 will ship with a new testing module (<code>quarkus-panache-mock</code>) that will make mocking Panache entities a breeze.
If you are eager to see what this feature is all about, check out <a href="https://github.com/quarkusio/quarkus/blob/3a5680ea367c5dad60655dcef0ca9765f14d5efe/docs/src/main/asciidoc/getting-started-testing.adoc#73-mocking-with-panache">this</a>
and feel free to give us early feedback.</p>
</div>
</div>
</div>
              
          </div>
          <div class="width-12-12"><div class="share-page">
  <a class="share-linkedin" href="https://www.linkedin.com/shareArticle?mini=true&url=https://quarkus.io/blog/mocking/&title=Mocking CDI beans in Quarkus" rel="nofollow" target="_blank" title="Share on LinkedIn">
    <img src="/assets/images/share-page/icons_social-linkedin.png"/>
  </a>
  <a class="share-twitter" href="https://twitter.com/intent/tweet?text=Mocking CDI beans in Quarkus&url=https://quarkus.io/blog/mocking/&via=quarkusio&related=quarkusio" rel="nofollow" target="_blank" title="Share on Twitter">
    <img src="/assets/images/share-page/icons_social-twitter.png"/>
  </a>
  <a class="share-facebook" href="https://facebook.com/sharer.php?u=https://quarkus.io/blog/mocking/" rel="nofollow" target="_blank" title="Share on Facebook">
    <img src="/assets/images/share-page/icons_social-facebook.png"/>
  </a>
  <a class="share-reddit" href="http://www.reddit.com/submit?url=https://quarkus.io/blog/mocking/" onclick="window.open(this.href, 'pop-up', 'left=20,top=20,width=900,height=500,toolbar=1,resizable=0'); return false;" title="Share on Reddit" >
    <img src="/assets/images/share-page/icons_social-reddit.png"/>
  </a>
  <a class="share-email" href="mailto:?subject=Mocking CDI beans in Quarkus&amp;body=Mocking CDI beans in Quarkus https://quarkus.io/blog/mocking/" title="Share via Email" >
    <img src="/assets/images/share-page/icons_social-email.png"/>
  </a>
</div>
</div>
        </div>
      </div>
    </div>
  </div>
</div>

  </div>

  <div class="content project-footer">
  <div class="footer-section">
    <div class="logo-wrapper">
      <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_reverse.svg" class="project-logo" title="Quarkus"></a>
    </div>
  </div>
  <div class="grid-wrapper">
    <p class="grid__item width-3-12">Quarkus is open. All dependencies of this project are available under the <a href='https://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache Software License 2.0</a> or compatible license.<br /><br />This website was built with <a href='https://jekyllrb.com/' target='_blank'>Jekyll</a>, is hosted on <a href='https://pages.github.com/' target='_blank'>Github Pages</a> and is completely open source. If you want to make it better, <a href='https://github.com/quarkusio/quarkusio.github.io' target='_blank'>fork the website</a> and show us what you’ve got.</p>

    
      <div class="width-1-12 project-links">
        <span>Navigation</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="/">Home</a></li>
          
            <li><a href="/guides">Guides</a></li>
          
            <li><a href="/community/#contributing">Contribute</a></li>
          
            <li><a href="/faq">FAQ</a></li>
          
            <li><a href="/get-started">Get Started</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Contribute</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://twitter.com/quarkusio">Follow us</a></li>
          
            <li><a href="https://github.com/quarkusio">GitHub</a></li>
          
            <li><a href="/security">Security&nbsp;policy</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Get Help</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://groups.google.com/forum/#!forum/quarkus-dev">Forums</a></li>
          
            <li><a href="https://quarkusio.zulipchat.com">Chatroom</a></li>
          
        </ul>
      </div>
    

    
      <div class="width-3-12 more-links">
        <span>Quarkus is made of community projects</span>
        <ul class="footer-links">
          
            <li><a href="https://vertx.io/" target="_blank">Eclipse Vert.x</a></li>
          
            <li><a href="https://microprofile.io" target="_blank">Eclipse MicroProfile</a></li>
          
            <li><a href="https://hibernate.org" target="_blank">Hibernate</a></li>
          
            <li><a href="https://netty.io" target="_blank">Netty</a></li>
          
            <li><a href="https://resteasy.github.io" target="_blank">RESTEasy</a></li>
          
            <li><a href="https://camel.apache.org" target="_blank">Apache Camel</a></li>
          
            <li><a href="https://code.quarkus.io/" target="_blank">And many more...</a></li>
          
        </ul>
      </div>
    
  </div>
</div>
  <div class="content redhat-footer">
  <div class="grid-wrapper">
    <span class="licence">
      <i class="fab fa-creative-commons"></i><i class="fab fa-creative-commons-by"></i> <a href="https://creativecommons.org/licenses/by/3.0/" target="_blank">CC by 3.0</a> | <a href="https://www.redhat.com/en/about/privacy-policy">Privacy Policy</a>
    </span>
    <span class="redhat">
      Sponsored by
    </span>
    <span class="redhat-logo">
      <a href="https://www.redhat.com/" target="_blank"><img src="/assets/images/redhat_reversed.svg"></a>
    </span>
  </div>
</div>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" integrity="sha384-8gBf6Y4YYq7Jx97PIqmTwLPin4hxIzQw5aDmUg/DDhul9fFpbbLcLh3nTIIDJKhx" crossorigin="anonymous"></script>
  <script type="text/javascript" src="/assets/javascript/mobile-nav.js"></script>
  <script type="text/javascript" src="/assets/javascript/scroll-down.js"></script>
  <script src="/assets/javascript/satellite.js" type="text/javascript"></script>
  <script src="https://quarkus.io/guides/javascript/config.js" type="text/javascript"></script>
  <script src="/assets/javascript/search-filter.js" type="text/javascript"></script>
  <script src="/assets/javascript/back-to-top.js" type="text/javascript"></script>
</body>

</html>
